/**
 * Created by Administrator on 2017/6/30 0030.
 */
"use strict";

angular.module('app.yksensor').controller('YKSimCtrl', function ($scope) {

    //配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 5,
        totalItems: 20,
        perPageOptions: [10, 20, 30, 40, 50],

        onChange: function () {
        }
    };

    //var socket = io.connect('http://192.168.1.233:3000');
    //socket.on('connect', function () {
    //    console.log("connect to server");

    //});

    myAppGlobal.websockets.sensorSocket.emit('select_device');

    myAppGlobal.websockets.sensorSocket.on('select_device_return', function (data) {

        $scope.alldevice = data;
        console.log($scope.alldevice);
        console.log("sssssssssss");

    })

    $scope.select = function () {

        myAppGlobal.websockets.sensorSocket.emit('data_sim_select', $scope.paginationConf);
        console.log("select.seclect");
     
    }

    $scope.insert = {};
    $scope.insertdata = function () {

       myAppGlobal.websockets.sensorSocket.emit('data_sim_insert', $scope.insert);
    }
  
    $scope.updatedata = function () {
    
        myAppGlobal.websockets.sensorSocket.emit('data_sim_update', $scope.editdata);
          
     }

    $scope.editdata = {};
    $scope.showEditSim = function (data) {

          $scope.editdata.id = data.id;
          $scope.editdata.mobile = data.mobile;
          $scope.editdata.org = data.org;
          $scope.editdata.fee = data.fee;
          $scope.editdata.yys = data.yys;
          $scope.editdata.sim = data.sim;
          $scope.editdata.deviceid = data.deviceid;
          //$scope.editdata.startday = data.startday;
          $scope.editdata.flow = data.flow;
          $scope.editdata.ywlx = data.ywlx;
          $scope.editdata.des = data.des;

          $('#editsim').modal('show');

      }

      $scope.delid = {};
      $scope.showDelDialog = function (id) {
        
          $scope.delid.id = id;
          $('#showDelDialog').modal('show');

      }

      $scope.delsim = function () {

          myAppGlobal.websockets.sensorSocket.emit('data_sim_delete', $scope.delid);
          $('#showDelDialog').modal('hide');
      }

     var leave = function () {
        window.location.href = "about:blank";
        window.close()
        myAppGlobal.websockets.sensorSocket.emit('leave', 'leave');
    }

     
     myAppGlobal.websockets.sensorSocket.on('success', function (data) {
        
         $.smallBox({
             title: "操作成功",
             content: "<i class='fa fa-clock-o'></i> <i>操作成功</i>",
             color: "#659265",
             iconSmall: "fa fa-check fa-2x fadeInRight animated",
             timeout: 4000
         });
         myAppGlobal.websockets.sensorSocket.emit('data_sim_select', $scope.paginationConf);
     })

    //接收来自服务端的信息事件c_hi
     myAppGlobal.websockets.sensorSocket.on('data_sim', function (msg,pagecount) {
        $scope.datas = msg;
        $scope.paginationConf.totalItems = pagecount;
       
      })

    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', $scope.select);
});
